package cn.imvc.app.controllers.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.Notice;
import cn.imvc.app.models.NoticeModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class NoticedControllerImpl implements NoticeController {

	public Page<Notice> page;
	public ViewRequest viewRequest;
	public Notice notice;
	public int id;
	public int[] ids;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public Notice getNotice() {
		return notice;
	}

	public void setNotice(Notice notice) {
		this.notice = notice;
	}

	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	@Autowired
	NoticeModel noticeModel;

	public String search() {
		return "noticed/search";
	}

	public String index() {

		page = noticeModel.find(viewRequest);
		return "noticed/index";
	}

	public String show() {
		notice = noticeModel.get(getId());
		return "noticed/show";
	}

	public String editNew() {
		return "noticed/editNew";
	}

	public String create() {
		noticeModel.save(notice);
		return Render.json(new DialogBean("200", "创建成功","noticed", "closeCurrent"));
	}

	public String edit() {
		notice = noticeModel.get(getId());
		return "noticed/edit";
	}

	public String update() {
		notice.setId(getId());
		noticeModel.update(notice);
		return Render.json(new DialogBean("200", "修改成功","noticed", "closeCurrent"));
	}

	public String destroy() {
		noticeModel.delete(getId());
		return Render.json(new DialogBean("200", "删除成功","noticed"));
	}

	public String destroyBatch() {
		noticeModel.deleteBatch(getIds());
		return Render.json(new DialogBean("200", "删除成功","noticed"));
	}

}